package com.xiaoyu.lanling.view.adapter;

import java.util.Collections;

import in.srain.cube.views.list.CubeRecyclerViewSimpleAdapter;
import in.srain.cube.views.list.ListItemTypedBase;

public class RecyclerViewDragAdapter<ItemDataType extends ListItemTypedBase> extends CubeRecyclerViewSimpleAdapter<ItemDataType> implements ItemTouchHelperAdapter {

    private ItemMovedListener movedListener;

    public RecyclerViewDragAdapter(ItemMovedListener movedListener) {
        this.movedListener = movedListener;
    }

    @Override
    public void onItemMove(int fromPosition, int toPosition) {
        //交换位置
        Collections.swap(getList(), fromPosition, toPosition);
        notifyItemMoved(fromPosition, toPosition);
    }

    @Override
    public void onItemMoved(int fromPosition, int toPosition) {
        movedListener.onItemMoved(fromPosition, toPosition);
    }

    @Override
    public void onItemDismiss(int position) {
        //移除数据
        getList().remove(position);
        notifyItemRemoved(position);
    }
}
